/*
* Copyright (c) 2007 by Kirill Kolodyazhniy.
* See the file "license.terms" for information on usage and redistribution.
*/

#ifndef M_SUBMESH_H
#define M_SUBMESH_H

#include "types.h"
#include "xmlreader.h"
#include "hardwarebuffer.h"

namespace Engine
{
	/**
	*   Class represent actual part of mesh with particular material.
	*/
	class SubMesh
	{
	public:

		SubMesh();

		SubMesh(const std::string& name);

		~SubMesh();

		const std::string& GetName() const;

		/**
		*   Return material.
		*/
        const MaterialPtr GetMaterial() const;

		/**
		*   Get index data.
		*/
		const HardWareBufferPtr GetIndexData()const;

		/**
		*   Read submesh.
		*/
		void Read(RefPtr<XmlElement> pElem);

		/**
		*   Get faces count.
		*/
		unsigned int GetFaceCount() const {return m_faceCount;}

	private:
		/**
		*   Read xml definition
		*	<submesh material = "mat2.material">
		*	...
		*	</submesh>
		*/
		void ReadSubMeshAttributes(const std::string& name, const std::string& value);

		/**
		*   Read xml definition
		*	<submesh material = "mat2.material">
		*		<faces count = "354">
		*			<face v1="0" v2="1" v3="2" />
		*		</faces>
		*	</submesh>
		*/
		void ReadSubMesh(RefPtr<XmlElement> pElem,const std::string& name);

	private:

		std::string m_name;
        RefPtr<HardWareBuffer,WeakPtrExtension> m_indexData;
		MaterialPtr m_material;
		unsigned short* m_indexDataPtr;
		unsigned int m_faceCount;
	};
}

#endif
